<script>
import { mapGetters, mapState } from 'vuex'
export default {
  data() {
    return {
      // 地址信息对象
      // address: {},
    }
  },

  methods: {
    async fn() {
      // console.log(111)
      // wx.chooseAddress
      // uni在这个api的处理上(需要查看文档) => 只适配大部分小程序(不适配h5 app) => 他没处理别的平台 如果我们将来就是要跨端 那么手动处理
      const res = await uni.chooseAddress()
      // console.log(res)
      // this.address = res
      this.$store.commit('user/setAddress', res)
    },
  },

  computed: {
    ...mapState('user', ['address']),
    ...mapGetters('user', ['fullAddress']),

    // fullAddress() {
    //   const { provinceName, cityName, countyName, detailInfo } = this.address

    //   if(!provinceName) return ''

    //   return provinceName + cityName + countyName + detailInfo
    // },
  },
}
</script>

<template>
  <view>
    <!-- 选择收货地址的盒子 -->
    <view v-if="JSON.stringify(address) === '{}'" class="address-choose-box">
      <button type="primary" size="mini" class="btnChooseAddress" @click="fn">
        请选择收货地址+
      </button>
    </view>

    <!-- 渲染收货信息的盒子 -->
    <view v-else class="address-info-box" @click="fn">
      <view class="row1">
        <view class="row1-left">
          <view class="username"
            >收货人：<text>{{ address.userName }}</text></view
          >
        </view>
        <view class="row1-right">
          <view class="phone"
            >电话：<text>{{ address.telNumber }}</text></view
          >
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
      </view>

      <view class="row2">
        <view class="row2-left">收货地址：</view>
        <view class="row2-right">{{ fullAddress }} </view>
      </view>
    </view>

    <!-- 底部的边框线 -->
    <view class="address-border"></view>
  </view>
</template>

<style scoped lang="scss">
// 底部边框线的样式
.address-border {
  display: block;
  width: 100%;
  height: 10rpx;
  border-bottom: 1rpx solid #efefef;
}

// 选择收货地址的盒子
.address-choose-box {
  height: 180rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

// 渲染收货信息的盒子
.address-info-box {
  font-size: 24rpx;
  height: 180rpx;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 10rpx;

  // 第一行
  .row1 {
    display: flex;
    justify-content: space-between;

    .row1-right {
      display: flex;
      align-items: center;

      .phone {
        margin-right: 10rpx;
      }
    }
  }

  // 第二行
  .row2 {
    display: flex;
    align-items: center;
    margin-top: 20rpx;

    .row2-left {
      white-space: nowrap;
    }
  }
}
</style>
